﻿
@model DHQGHN.PM2.Models.Online.ChetMatTichModel

<script>
    @functions{
        public string GetAntiForgeryToken()
        {
            string cookieToken, formToken;
            AntiForgery.GetTokens(null, out cookieToken, out formToken);
            return cookieToken + "," + formToken;
        }
    };
    jQuery(function ($) {
        Checkngay("DAYDEATH");
        Checkthang("MONTHDEATH");
        Checknam("YEARDEATH");
        Checkngay("DAYMISSING");
        Checkthang("MONTHMISSING");
        Checknam("YEARMISSING");
        $("#divLoading").show();
        $("#btnNext").attr("disabled", "disabled");
        $("#btnBack").attr("disabled", "disabled");
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'DEATH_CAUSE' },
            success: function (data, textStatus, jqXHR) {
                $(".DEATH_CAUSE_ID").append('<option value="">' +
      '-- Chọn Nguyên nhân --' + '</option>');
                $.each(data, function (i, item) {
                    $(".DEATH_CAUSE_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');
                });
                $(".DEATH_CAUSE_ID").val("@Model.DEATH_CAUSE_ID");
            },
            complete: function (jqXHR, textStatus) {
                $("#divLoading").hide();
                $("#btnNext").removeAttr("disabled");
                $("#btnBack").removeAttr("disabled");
            },

        });

    });


    function ClickButton(Next) {
        var ngayde = $("#DAYDEATH").val();
        var thangde = $("#MONTHDEATH").val();
        var namde = $("#YEARDEATH").val();
        var ngaymi = $("#DAYMISSING").val();
        var thangmi = $("#MONTHMISSING").val();
        var nammi = $("#YEARMISSING").val();
        var tmp = $('#row' + $("#RESIDENT_ID").val());
        var rownext = tmp.next();
        var residentNextId = rownext.attr("resident_id");
        if (residentNextId == null || residentNextId.length <= 0) {
            residentNextId = "-1";
        }

        var dataSend = {
            'RESIDENT_ID': $('#selectMenu').val(),
            'DEATH_DATE': namde + thangde + ngayde,
            'DEATH_CAUSE_ID': $(".DEATH_CAUSE_ID").val(),
            'MISSING_DATE': nammi + thangmi + ngaymi,
            'ResidentNextId': residentNextId,
            'NEXT': Next,

        };
        var jqXHR = $.ajax({
            url: '@Url.Action("ChatMattichNew","Online")',
            dataType: 'html',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'post',
            cache: false,
            data: dataSend,
            success: function myfunctionSuccess(data, textStatus, jqXHR) {
                $('#mainForm').html(data);
            },
            complete: function (jqXHR, textStatus) {
                if (Next == '1') {
                    $('#thongtin').text("HOÀN THÀNH");
                } else {
                    $('#thongtin').text("THÔNG TIN BẢO HIỂM");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Có lỗi xảy ra trong quá trình lưu thông tin: ' + errorThrown);
            },

        });
    }
    $("#btnNext").click(function (event, giatri) {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            if (giatri != null) {
                ClickButton(giatri);
            }
            else {
                if (Checkdatetime("DAYDEATH", "MONTHDEATH", "YEARDEATH") == 0 && Checkdatetime("DAYMISSING", "MONTHMISSING", "YEARMISSING") == 0) {
                    ClickButton(1);
                    var ctr = $('.mnResident');
                    var menu = ctr.find('#mainmenu');
                    var menuItem = menu.find(".active");
                    var menuNext = menuItem.next();
                    if (menuNext.length > 0) {
                        menu.find('.menuitem').removeClass("active");
                        menuNext.addClass("active");

                        var resident_id = menuNext.attr('resident_id');
                        var selectMenu = ctr.find('#selectMenu');
                        selectMenu.val(resident_id);
                        ResidentDetail.loadForm(resident_id);
                    }
                    else {
                        window.location.href = '@Url.Action("SubmitNew","Online")';
                    }
                }
            }
        }
    });
    $("#btnBack").click(function () {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            ClickButton(0);
        }
    });
</script>

<div class="row margin-top-20">
    <div class="col-md-12">
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Ngày chết</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.DAYDEATH, new { @class = "form-control", style = "width: 15%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.DAYDEATH) })/@Html.TextBoxFor(model => model.MONTHDEATH, new { @class = "form-control", style = "width: 15%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.MONTHDEATH) })/@Html.TextBoxFor(model => model.YEARDEATH, new { @class = "form-control", style = "width: 20%; display: inline;", MaxLength = 4, @title = @Html.ToolTipMessageFor(m => m.YEARDEATH) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Nguyên nhân chết</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="DEATH_CAUSE_ID form-control " style="width:52%;"></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Ngày mất tích</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.DAYMISSING, new { @class = "form-control", style = "width: 15%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.DAYMISSING) })/@Html.TextBoxFor(model => model.MONTHMISSING, new { @class = "form-control", style = "width: 15%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.MONTHMISSING) })/@Html.TextBoxFor(model => model.YEARMISSING, new { @class = "form-control", style = "width: 20%; display: inline;", MaxLength = 4, @title = @Html.ToolTipMessageFor(m => m.YEARMISSING) })
            </div>
        </div>
    </div>
</div>
<div class=" row margin-top-20">
    <div style="text-align:center; margin-top:30px;">
        <button class="btn btn-sm" id="btnBack" style="background-color: #2664B7; color:#ffffff; min-width:100px;"><i class="fa fa-angle-double-left"></i> Quay lại</button>
        <button class="btn btn-sm" id="btnNext" style="background-color: #2664B7; color:#ffffff; min-width:100px;">Tiếp tục <i class="fa fa-angle-double-right"></i></button>
    </div>
</div>



